package com.lianxi.jdbc;

import org.apache.tomcat.dbcp.dbcp.BasicDataSource;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * Created by Administrator on 2018/4/26 0026.
 */
public class OracleDBHelper {
     private static BasicDataSource ds = new BasicDataSource();
    static {
        String driver = "oracle.jdbc.driver.OracleDriver";
        // 人防办
        /*String driver = "oracle.jdbc.driver.OracleDriver";
        String url = "jdbc:oracle:thin:@//10.10.10.249:21521/PDB1";
        String user = "HNRFBCMS2015";
        String pwd = "HNRFBCMS2015";*/
        // 水利厅老数据库
        /*String driver = "oracle.jdbc.driver.OracleDriver";
        String url = "jdbc:oracle:thin:@//10.10.10.249:21521/PDB1";
        String user = "HNSSLT";*/
        // 纤维局数据库
        /*String url = "jdbc:oracle:thin:@//10.10.10.249:21521/PDB1";
        String user = "HNSZJJ1";
        String pwd = "FdSzVg5xy6Mo";*/
        // 安阳市发展改革委
        String url = "jdbc:oracle:thin:@//10.10.10.249:21521/PDB1";
        String user = "AYSZF3";
        String pwd = "q8cmp6d9m8s";

        String initSize = "3";
        String maxSize = "60000";
        //创建连接池
        ds = new BasicDataSource();
        //设置参数
        ds.setDriverClassName(driver);
        ds.setUrl(url);
        ds.setUsername(user);
        ds.setPassword(pwd);
        ds.setInitialSize(new Integer(initSize));
        ds.setMaxActive(new Integer(maxSize));
    }

    public static Connection getConnection() throws SQLException {
        return ds.getConnection();
    }

    public static void close(Connection conn){
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
                throw new RuntimeException("关闭连接失败",e);
            }
        }
    }



}
